//
//  LocalNotificationExampleViewController.m
//  LocalNotificationExample
//

#import "LocalNotificationExampleViewController.h"

int badgeNumber;

@implementation LocalNotificationExampleViewController

- (void)createNotification:(id) sender {
	NSTimeInterval ss = 10;
	NSDate *notificationDate = [NSDate dateWithTimeIntervalSinceNow:ss];
	
	UILocalNotification *note = [[UILocalNotification alloc] init];
	note.fireDate = notificationDate;
	note.timeZone = [NSTimeZone defaultTimeZone];
	
	note.alertBody = @"The Notification Body";
	note.alertAction = @"View";
	note.soundName = UILocalNotificationDefaultSoundName;
	
	badgeNumber++;
	note.applicationIconBadgeNumber = badgeNumber;
	
	NSDictionary *dict = [NSDictionary dictionaryWithObject:@"Joe Smith" forKey:@"username"];
	note.userInfo = dict;
	
	[[UIApplication sharedApplication] scheduleLocalNotification:note];
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
	UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	CGRect buttonRect = CGRectMake(75,50,150,35);
	[btn setFrame:buttonRect];
	[btn setTitle:@"Create Notification" forState:UIControlStateNormal];
	[btn addTarget:self action:@selector(createNotification:) forControlEvents:UIControlEventTouchDown];
	[self.view addSubview:btn];
}

- (void)dealloc {
    [super dealloc];
}

@end
